using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace ArchSoft
{
    public partial class MyTree : TreeView
    {
        #region " Construction "

        public MyTree()
        {
            InitializeComponent();
            //SolTree();
        }

        #endregion
        

        #region " Propertise! "

        private string MainPathStr_ = "";
        public string MainPathStr
        {
            set 
            {
                if (!Directory.Exists(value))
                    this.MainPathStr_ = "";
                else
                    this.MainPathStr_ = value;
            }
            get { return this.MainPathStr_; }
        }

        #endregion

        public virtual void SolTree() 
        {
            if (this.MainPathStr_ != "")
            {
                this.Nodes.Clear();
                foreach (string fol in Directory.GetDirectories(MainPathStr_))
                {
                    GetNodes(fol, null);
                }
            }
        }

        void GetNodes(string Fol,TreeNode Papa)
        {
            TreeNode nod = null;
            if (Papa == null)
                nod = this.Nodes.Add(Fol);
            else
                nod = Papa.Nodes.Add(Fol);
            foreach (string fol in Directory.GetDirectories(MainPathStr_))
            {
                GetNodes(fol, nod);
            }
        }
    }
}
